package com.lingnan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lingnan.entity.po.JobSeeker;
import org.apache.ibatis.annotations.*;

public interface JobSeekerMapper extends BaseMapper<JobSeeker> {

    /**
     * 根据求职者ID查询详细信息（包含简历）
     */
    @Select("SELECT js.*, r.id as resume_id, r.title as resume_title, r.is_default " +
            "FROM job_seeker js " +
            "LEFT JOIN resume r ON js.id = r.seeker_id " +
            "WHERE js.id = #{seekerId}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "resumes", column = "id",
                    many = @Many(select = "com.lingnan.mapper.ResumeMapper.selectBySeekerIdList"))
    })
    JobSeeker selectWithResumes(@Param("seekerId") Long seekerId);

    /**
     * 检查求职者是否有投递记录
     */
    @Select("SELECT COUNT(*) FROM job_application WHERE seeker_id = #{seekerId}")
    int countApplicationsBySeekerIdd(@Param("seekerId") Long seekerId);

    /**
     * 检查求职者是否有面试记录
     */
    @Select("SELECT COUNT(*) FROM interview i " +
            "INNER JOIN job_application ja ON i.application_id = ja.id " +
            "WHERE ja.seeker_id = #{seekerId}")
    int countInterviewsBySeekerIdd(@Param("seekerId") Long seekerId);
    JobSeeker selectByUserId(Long senderId);
}
